package com.zh.media.controller;

import com.zh.common.annotation.Operator;
import com.zh.media.domain.dto.AddReplyDto;
import com.zh.media.domain.dto.PageReplyDto;
import com.zh.media.domain.vo.ReplyVo;
import com.zh.media.service.ReplyService;
import com.zh.web.base.ApiResult;
import com.zh.web.base.BaseController;
import com.zh.web.base.PageApiResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

@Api(tags = "回复接口")
@Slf4j
@RequestMapping("/reply")
@RequiredArgsConstructor
@RestController
@Validated
@Operator
public class ReplyController extends BaseController {

    private final ReplyService replyService;

    @PostMapping("/page")
    @ApiOperation(value = "回复分页查询")
    @ApiImplicitParams(
            @ApiImplicitParam(name = "Authorization", value = "Bearer token", required = false, dataType = "string", paramType = "header")
    )
    public ApiResult<PageApiResult<ReplyVo>> pageReply(@RequestBody PageReplyDto pageReplyDto, HttpServletRequest request) {
        return buildSuccessPackage(replyService.pageReply(pageReplyDto, request));
    }

    @GetMapping
    @ApiOperation(value = "回复详情")
    public ApiResult<ReplyVo> getReply(@RequestParam("id") Long id) {
        return buildSuccessPackage(replyService.getReplyVo(id));
    }

    @PostMapping
    @ApiOperation(value = "新增回复")
    public ApiResult<String> addReply(@Valid @RequestBody AddReplyDto addReplyDto) {
        return buildMsgPackage(replyService.save(addReplyDto));
    }

    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除回复")
    public ApiResult<String> deleteReply(@PathVariable("id") Long id) {
        return buildMsgPackage(replyService.delete(id));
    }


}
